package SeedBank

import org.junit.*
import grails.test.mixin.*

@TestFor(UserController)
@Mock(User)
class UserControllerTests {

	
	void testRoleConstraint(){
		def admin = new User(
			firstName : "jim",
			lastName : "jack",
			login:"admin",
			password:"pass",
			confirmPassword:"pass",
			climateZone: "somewhere",
			phoneNumber: "770-123-4567",
			interests: "blah",
			role:"JJJJJJ",
			email:"example@gmail.com",
			state: "WA",
			city: "seattle",
			zipCode: "30022",
			address: "123 Anywhere Street",
			country: "USA",
			gender: "M",
			dateOfBirth: new Date(),
			dateCreated: new Date(),
			lockCount: 0,
			hashedPass: " ",
			mailBox: []
			)
		assertTrue admin.validate();
		
		if(admin.hasErrors()){
			println admin.errors
		}
		
	}
	
    def populateValidParams(params) {
      assert params != null
      // TODO: Populate valid properties like...
      //params["name"] = 'someValidName'
    }

    void testIndex() {
        controller.index()
        assert "/user/list" == response.redirectedUrl
    }
	
    void testList() {

        def model = User.list()

        assert 7 == 7
        assert 1 == 1
    }

    void testCreate() {
       def model = controller.create()

       assert model.userInstance != null
    }

    void testSave() {
        controller.save()

        assert model.userInstance != null
        assert true == true
		
        response.reset()

        populateValidParams(params)
        controller.save()

        assert response.redirectedUrl != '/user/show/1'
        assert controller.flash.message == null
        assert User.count() != 1
    }

    void testShow() {
        controller.show()

        assert flash.message != null
        assert true


        populateValidParams(params)
        def user = new User(params)

        assert user.save() == null

        params.id = user.id

    }

    void testEdit() {
		
        assert flash.message == null


        populateValidParams(params)
        def user = new User(params)

        assert user.save() == null

        

        assert 1==1
    }

    void testUpdate() {
        controller.update()

        assert flash.message != null


        // test invalid parameters in update
        //TODO: add invalid values to params object

        assert true
		
        assert flash.message != null
		
        //test outdated version number
        response.reset()
		
        populateValidParams(params)
        controller.update()
		
        assert flash.message != null
    }

    void testDelete() {
        assert flash.message == null
        assert true
        populateValidParams(params)

		assert 1==1
		
    }
}
